/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2016年7月5日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package obsver;

import java.util.ArrayList;
import java.util.List;

/**
 * @Type ContentUpdateCatcher
 * @Desc
 * @author boboge
 * @date 2016年7月5日
 * @Version V1.0
 */
public class ContentUpdateCatcher implements Subject {

    private String catchContent;

    public String getCatchContent() {
        return catchContent;
    }

    public void setCatchContent(String catchContent) {
        this.catchContent = catchContent;
    }

    List<Observer> observers = new ArrayList<>();

    /*
     * (non-Javadoc)
     * 
     * @see obsver.Subject#add(obsver.Observer)
     */
    @Override
    public void add(Observer observer) {
        observers.add(observer);
    }

    /*
     * (non-Javadoc)
     * 
     * @see obsver.Subject#remove(obsver.Observer)
     */
    @Override
    public void remove(Observer observer) {
        observers.remove(observer);
    }

    /*
     * (non-Javadoc)
     * 
     * @see obsver.Subject#notifyUser()
     */
    @Override
    public void notifyUser() {

        CatchMsg();
        for (Observer observer : observers) {
            observer.receiveMsg(getCatchContent());
        }
    }

    /**
     * 
     */
    private void CatchMsg() {
        setCatchContent("抓取的内容");
    }

}
